package com.lry.basic.proxy.demo3;

import com.lry.basic.proxy.demo2.anno.Feign;
import com.lry.basic.proxy.demo2.anno.RequestMapping;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class Test {

    public static void main(String[] args) {

        UserService userService = (UserService) JProxy.newProxyInstance( UserService.class, new JInvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                System.out.println("代理对象："+proxy);
                Feign feign = method.getDeclaringClass().getAnnotation(Feign.class);
                String serviceName = feign.serviceName();
                RequestMapping requestMapping =  method.getAnnotation(RequestMapping.class);
                String url = requestMapping.url();
                url = serviceName+url;
                System.out.println(url);
                System.out.println(args[0]);
                return null;
            }
        });

        System.out.println(userService);
        userService.queryUserById(1);

    }



}
